<template>
	<el-container>
				<el-header style="height:150px">
						<el-steps :active="2" align-center style="width:80%" >
							<el-step title="创建新场景" description="开始新的重保配置" />
							<el-step title="子场景" description="场馆配置、网元配置、告警配置、区域信息、施工单位" />
							<el-step title="配置人员" description="组织架构、保障通讯录配置等" />
							<el-step title="配置物资仓库" description="仓库配置、物资大类、物资小类、物料、应急物资等" />
							<el-step title="完成" description="开始使用" />
						</el-steps>
				</el-header>
		<el-form  ref="form" :label-width="120" style="width:80%">
			<el-form-item label="场景" prop="user">
				<el-input placeholder="请输入"></el-input>
				<div class="el-form-item-msg">请输入注册时填写的登录账号</div>
			</el-form-item>
			<!-- <el-form-item label="手机号码" prop="phone">
				<el-input v-model="form.phone" placeholder="请输入手机号码"></el-input>
			</el-form-item>
			<el-form-item label="短信验证码" prop="yzm">
				<div class="yzm">
					<el-input v-model="form.yzm" placeholder="请输入6位短信验证码"></el-input>
					<el-button @click="getYzm" :disabled="disabled">获取验证码<span v-if="disabled"> ({{time}})</span></el-button>
				</div>
			</el-form-item> -->
			<el-form-item label="子场景" prop="newpw">
				<el-input  show-password placeholder="请输入"></el-input>
				<div class="el-form-item-msg">请输入包含英文、数字的8位以上密码</div>
			</el-form-item>
			<el-form-item label="场馆" prop="newpw">
				<el-input  show-password placeholder="请输入"></el-input>
				<div class="el-form-item-msg">请输入包含英文、数字的8位以上密码</div>
			</el-form-item>
			<el-form-item label="网元" prop="newpw2">
				<el-input  show-password placeholder="请输入"></el-input>
			</el-form-item>
			<el-form-item label="区域" prop="newpw2">
				<el-input  show-password placeholder="请输入"></el-input>
			</el-form-item>
			<el-form-item label="施工单位" prop="newpw2">
				<el-input  show-password placeholder="请输入"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="save">下一步</el-button>
			</el-form-item>
		</el-form>
	</el-container>

	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>

</template>

<script>
	import saveDialog from './save'

	export default {
		name: 'user',
		components: {
			saveDialog
		},
		data() {
			return {
				dialog: {
					save: false
				},
				showGrouploading: false,
				groupFilterText: '',
				group: [],
				apiObj: this.$API.system.user.list,
				selection: [],
				search: {
					keyword: null
				}
			}
		},
		watch: {
			groupFilterText(val) {
				this.$refs.group.filter(val);
			}
		},
		mounted() {
			this.getGroup()
		},
		methods: {
			//添加
			add(){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.saveDialog.open()
				})
			},
			//编辑
			table_edit(row){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.saveDialog.open('edit').setData(row)
				})
			},
			//查看
			table_show(row){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.saveDialog.open('show').setData(row)
				})
			},
			//删除
			async table_del(row, index){
				var reqData = {userIds: [row.id], userName:row.userName}
				var res = await this.$API.system.user.delete.delete(reqData);
				if(res.code == 200){
					//这里选择刷新整个表格 OR 插入/编辑现有表格数据
					this.$refs.table.tableData.splice(index, 1);
					this.$message.success("删除成功")
				}else{
					this.$alert(res.message, "提示", {type: 'error'})
				}
			},
			//批量删除
			batch_del(){
				this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, '提示', {
					type: 'warning'
				}).then(async() => {
					const loading = this.$loading();
					// this.selection.forEach(item => {
					// 	this.$refs.table.tableData.forEach((itemI, indexI) => {
					// 		if (item.id === itemI.id) {
					// 			this.$refs.table.tableData.splice(indexI, 1)
					// 		}
					// 	})
					// })
					var userIds = []
					this.selection.forEach(item => {
						userIds.push(item.id)
					})
					let reqData={userIds:userIds}
					var res = await this.$API.system.user.delete.delete(reqData)
					loading.close();
					if(res.code == 200){
						this.$refs.table.refresh()
						this.$message.success("删除成功")
					}else{
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}).catch(() => {

				})
			},
			//表格选择后回调事件
			selectionChange(selection){
				this.selection = selection;
			},
			//加载树数据
			async getGroup(){
				this.showGrouploading = true;
				var res = await this.$API.system.dept.list.get();
				this.showGrouploading = false;
				var allNode ={id: '', label: '所有'}
				res.data.unshift(allNode);
				this.group = res.data;
			},
			//树过滤
			groupFilterNode(value, data){
				if (!value) return true;
				return data.label.indexOf(value) !== -1;
			},
			//树点击事件
			groupClick(data){
				var params = {
					groupId: data.id
				}
				this.$refs.table.reload(params)
			},
			//搜索
			upsearch(){
				this.$refs.table.upData(this.search)
			},
			handleResetPassword() {
				this.$confirm(`确定将选中的 ${this.selection.length} 项重置密码123456吗？`, '提示', {
					type: 'warning'
				}).then(async() => {
					const loading = this.$loading();
					var userIds = []
					this.selection.forEach(item => {
						userIds.push(item.id)
					})
					let param={'userIds':userIds}
					var res = await this.$API.system.user.resetpassword.put(param);
					loading.close();
					if(res.code == 200){
						this.$message.success("删除成功")
					}else{
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}).catch(() => {
				})
			},
			//本地更新数据
			handleSuccess(data, mode){
				if(mode=='add'){
					// data.id = new Date().getTime()
					// this.$refs.table.tableData.unshift(data)
					this.$refs.table.refresh()
				}else if(mode=='edit'){
					// this.$refs.table.tableData.filter(item => item.id===data.id ).forEach(item => {
					// 	Object.assign(item, data)
					// })
					this.$refs.table.refresh()
				}
			}
		}
	}
</script>

<style>
</style>
